package cn.myjerry.others.guava;

import java.util.Set;

import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;

/**
 * 集合的操作：交集、差集、并集
 * Sets.intersection()
 * Sets.difference()
 * Sets.union()
 * @author Jerry
 *
 */
public class Demo04 {
	public static void main(String[] args) {
		Set<Integer> sets = Sets.newHashSet(1,2,3,4,5);
		Set<Integer> sets2 = Sets.newHashSet(3,4,5,6,7);
		// 交集
		System.out.println("交集:");
		SetView<Integer> intersection = Sets.intersection(sets, sets2);
		for(Integer item:intersection) {
			System.out.println(item);
		}
		// 差集
		System.out.println("差集:");
		SetView<Integer> difference =  Sets.difference(sets, sets2);
		for(Integer item:difference) {
			System.out.println(item);
		}
		// 并集
		System.out.println("并集:");
		SetView<Integer> union = Sets.union(sets, sets2);
		for(Integer item:union) {
			System.out.println(item);
		}
	}
}
